import Vue from 'vue'
const  sys = {
    install(Vue){
        Vue.prototype.$method={
            getUrl:function (param) {
                return process.env.IMG_URL + "/header/"+param;
            },
            getTimeShow(param){
                let minute = 1000 * 60 ;
                let hour = minute * 60;
                let day = hour *24;
                let week = day * 7;
                let month = day * 30;
                let time =  param.replace('T',' ');
                time = time.replace('-','/');
                time = time.split(".")[0];
                let timestamp  = new Date(time).getTime();
                let now = new Date().getTime();
                let show = now - timestamp;
                let monthC = show / month;
                let weekC = show / week;
                let dayC = show /day;
                let hourC = show /hour;
                let minC = show / minute;
                if (monthC >=1){
                    if (monthC >12){
                        param = param.split("T")[0];
                    }else {
                        param = parseInt(monthC) + "个月前";
                    }
                }else if (weekC >= 1){
                    param = parseInt(weekC)+"周前";
                }else if (dayC >= 1){
                    param = parseInt(dayC)+"天前";
                }else if (hourC >= 1){
                    param = parseInt(hourC)+"小时前";
                }else if (minC >= 1){
                        param = parseInt(minC)+"分钟前";

                }else {
                    param = "刚刚";
                }
                return param;
            },
            //得到帖子详情的方法
            topicInfo(id){
                    this.$axios.get("/api/topicInfo/"+id).then(res=>{
                    }).catch(reason => {});
            },
            saveData(response,store){

                store.commit('user/setIsLogin',true);
                store.commit('user/setUserHeader',process.env.IMG_URL+"/header/" + response.data.header);
                store.commit("user/setUsers",response.data);
            },
             resetContent(str){

             let  s =  str.replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;");
            //判断是否有shell命令
                 if (str.search("```") === -1){
                     s = s.replace(/\n/g,"<br>");
                 }
               return s;
            }
        };
    }
}
Vue.use(sys)